package com.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import static com.util.GlobalArgs.UserCookie_key;

/**
 * Created by Dell on 2018/3/1.
 */
public class CookieUtil {
    /**
     * 用于获取位于前端的Cookie
     * @param request
     * @return
     */
    public static Cookie getUserCookie(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        Cookie cookie = new Cookie("null",null);
        for (int i = 0; i < cookies.length;i++){
            if (cookies[i].getName().equals(UserCookie_key)){
                cookie = cookies[i];
                break;
            }
        }
        return cookie;
    }
}
